package bishi;

import java.util.Scanner;

/**
 * @Author liuhaoqi
 * @Date 2020/9/27 19:40
 * @Version 1.0
 */
public class WeiZhong03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < arr.length; i++) {
            int j = i + 1;
            int k = arr.length - 1;
            while (j < arr.length) {
                if (arr[i] > arr[j]) {
                    j++;
                    continue;
                }
                if (j == k) {
                    break;
                }
                if (arr[j] <= arr[k]) {
                    ans++;
                }
                k--;
                if (j == k) {
                    j++;
                    k = arr.length - 1;
                }
            }
        }
        System.out.println(ans);
    }
}




